import { defineMongooseModel } from "#nuxt/mongoose";
import mongoose from "mongoose";
export interface MenuDataProps {
  parentId: mongoose.Schema.Types.ObjectId;
  name: string;
  path: string;
  icon: string;
  order: number;
  createdAt: string;
  updatedAt: string;
}
export const MenuSchema = defineMongooseModel<MenuDataProps>(
  "Menu",
  {
    parentId: { type: mongoose.Schema.Types.ObjectId },
    name: { type: String },
    path: { type: String, unique: true },
    icon: { type: String },
    order: { type: Number, default: 0 },
  },
  {
    timestamps: true,
    toJSON: {
      // 过滤掉敏感字段
      transform(doc: any, ret: Record<string, any>, options: any) {
        delete ret.__v;
      },
    },
  }
);
